<?php

namespace app\api\controller;

use app\common\controller\BasicApi;
use app\common\model\GeneralModel;
use app\common\model\OrderModel;

class General extends BasicApi
{
   /**
    * 获取通用内容
    */
   public function getGeneral(){
       $general = GeneralModel::where('')->field('key,value')->select();
       if (!empty($general)) {
           $this->success('获取通用内容成功！', $general, 200);
       } else {
           $this->error('获取通用内容失败！', '', 400);
       }
   }

    /**
     * 获取通知公告
     */
    public function getNotice(){
        //获取最新五条订单记录
        $order = OrderModel::where('status',1)->order('id desc')->limit(5)->select();
        foreach ($order as $key=>$value) {
            $arr[] = '用户'.$value['user_id'].'成功购买！';
        }
        if (!empty($arr)) {
            $this->success('获取通知公告成功！', $arr, 200);
        } else {
            $this->error('获取通知公告失败！', '', 400);
        }
    }

    /**
     * 获取隐私政策
     */
    public function getRule(){
        $rule = GeneralModel::where('key','rule')->find();
        if (!empty($rule)) {
            $this->success('获取隐私政策成功！', $rule, 200);
        } else {
            $this->error('获取隐私政策失败！', '', 400);
        }
    }

    /**
     * 获取营业执照
     */
    public function getBusiness(){
        $business = GeneralModel::where('key','business')->find();
        if (!empty($business)) {
            $this->success('获取营业执照成功！', $business, 200);
        } else {
            $this->error('获取营业执照失败！', '', 400);
        }
    }

    /**
     * 获取用户协议
     */
    public function getAgreement(){
        $agreement = GeneralModel::where('key','agreement')->find();
        if (!empty($agreement)) {
            $this->success('获取用户协议成功！', $agreement, 200);
        } else {
            $this->error('获取用户协议失败！', '', 400);
        }
    }

}
